using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace QuanLyNganHangDe.DAL.Models.Mapping
{
    public class HocPhanMap : EntityTypeConfiguration<HocPhan>
    {
        public HocPhanMap()
        {
            // Primary Key
            this.HasKey(t => t.MaHocPhan);

            // Properties
            this.Property(t => t.MaHocPhan)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.TenHocPhan)
                .IsRequired()
                .HasMaxLength(255);

            this.Property(t => t.MaDonVi)
                .IsRequired()
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("HocPhan");
            this.Property(t => t.MaHocPhan).HasColumnName("MaHocPhan");
            this.Property(t => t.TenHocPhan).HasColumnName("TenHocPhan");
            this.Property(t => t.SoTinChi).HasColumnName("SoTinChi");
            this.Property(t => t.ThoiGianLamBai).HasColumnName("ThoiGianLamBai");
            this.Property(t => t.DuocSuDungTaiLieu).HasColumnName("DuocSuDungTaiLieu");
            this.Property(t => t.MaDonVi).HasColumnName("MaDonVi");

            // Relationships
            this.HasRequired(t => t.DonViPhuTrach)
                .WithMany(t => t.HocPhanCollection)
                .HasForeignKey(d => d.MaDonVi);

        }
    }
}
